package see.battle.test;
import see.battle.Const;
import see.battle.object.ShipContainer;
import junit.framework.TestCase;

public class ShipContainerTestCase extends TestCase {
	ShipContainer _container;
	
	public void setUp() {
	  _container = new ShipContainer(Const.fromLeftToRightDirection);
	  long t1 = (long)((0 - Const.backgroundLeft) / 
	      Const.shipSpeed) * Const.updateDelay;
    long t2 = (long)((0.5 - Const.backgroundLeft) / 
        Const.shipSpeed) * Const.updateDelay;
    long t3 = (long)((1 - Const.backgroundLeft) / 
        Const.shipSpeed) * Const.updateDelay;
    _container.initRandom(0);
    _container.addShip(null, null, t3 - t3, t3);
    _container.addShip(null, null, t3 - t2, t3);
    _container.addShip(null, null, t3 - t1, t3);
	}
	
	public void testProceedBullet() {
	  long res = 0;
	  float ds = ((float)1.0 - Const.backgroundSeaLevel) / 
	      Const.bulletSpeed * Const.shipSpeed;
	  res = _container.proceedBullet(ds);
	  assertEquals(res, -1);
    res = _container.proceedBullet(ds - Const.shipWidth / 2);
    assertEquals(res >= 0, true);
    res = _container.proceedBullet(ds - Const.shipWidth - (float)0.1);
    assertEquals(res, -1);
	}
	
	public void testUpdate() {
	  long t4 = (long)((Const.backgroundRight - Const.backgroundLeft + 
	      Const.shipWidth) / Const.shipSpeed + 2) * Const.updateDelay;
	  long t5 = t4 + (long)(0.5 / Const.shipSpeed) * Const.updateDelay;
    long t6 = t5 + (long)(0.5 / Const.shipSpeed) * Const.updateDelay;
	  assertEquals(_container.getShipsNumber(), 3);
    _container.updateShips(t4);
    assertEquals(_container.getShipsNumber(), 2);
    _container.updateShips(t5);
    assertEquals(_container.getShipsNumber(), 1);
    _container.updateShips(t6);
    assertEquals(_container.getShipsNumber(), 0);
	}
}
